home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!island!sun.com
- From: argv@sun.com (Dan Heller)
- Newsgroups: comp.sources.x
- Subject: v05i039: XView example programs, Part01/06
- Message-ID: <1239@island.uu.net>
- Date: 8 Dec 89 07:37:06 GMT
- Sender: argv@island.uu.net
- Lines: 1657
- Approved: island!argv@sun.com
-
- Submitted-by: Dan Heller <argv@sun.com>
- Posting-number: Volume 5, Issue 39
- Archive-name: xview.demos/part01
-
- This directory contains all the demo programs from the XView Programmer's
- Manual (XVPM), which is Volume 7 of the series of X books from O'Reilly
- Associates.
- The book should be available (in book stores) by January. XView will be
- distributed by Sun Microsystems and will also be on the X11R4 release.
- The XVPM and all its programs were written by me, Dan heller <argv@sun.com>.
-
- Contact xview@ora.uu.net for information on ordering books.
-
- Contact xviewbugs@sun.com for bugs with XView or other related questions.
-
- Buy the book if you have questions about any of the programs. :-)
- Or mail argv@sun.com or xviewbugs@sun.com for help.
-
- --------------
- What is XView?
- --------------
- Basically, XView is a toolkit for developing Open Look user interfaces
- for X11-based applications. It does *not* use the toolkit intrinsics,
- but it has a similar class-inheritance type system where you can build
- new packages based on existing ones. However, XView was written to make
- Open Look compliant applications, so you won't be able to write a Motif
- interface using XView, for example. You aren't required to use an Open
- Look window manager, but it'll help bring out some very important aspects
- of the toolkit.
-
- ----------------------------
- What's in this distribution?
- ----------------------------
- The sources include several directories for each XView "object".
- Objects include panels, canvases, frames, and so on. Each directory
- contains sample programs that focus on the particular packages. Also
- included are Makefiles and Imakefiles. The Imakefiles are the same
- as those that are going to be distirbuted by Sun and available on
- the X11R4 release of XView. The Imakefiles probably won't work
- right now unless you fiddle with them a little. The makefiles
- are pretty straightforward. Basically, most programs[%] compile as:
- cc program.c -lxview -lX11 -o program
- If the include files for your XView sources are not in /usr/include,
- then be sure to add -I"path" to the compile-line indicating the
- path to these include files.
-
- [%] There is one exception -- ttysw/ttycurses.c also uses the curses
- library demonstrating how you can use it with the terminal emulator window.
-
- File Name Archive # Description
- ----------------------------------------------------------
- xview.demos 1
- xview.demos/Imakefile 5
- xview.demos/canvas 1
- xview.demos/canvas/Imakefile 5
- xview.demos/canvas/Makefile 5
- xview.demos/canvas/canvas_event.c 3
- xview.demos/canvas/canvas_input.c 2
- xview.demos/canvas/line.c 5
- xview.demos/canvas/scroll_view.c 2
- xview.demos/canvas/split_views.c 2
- xview.demos/color 1
- xview.demos/color/Imakefile 5
- xview.demos/color/Makefile 6
- xview.demos/color/cardback.icon 4
- xview.demos/color/color.c 4
- xview.demos/color/color_animate.c 3
- xview.demos/color/color_logo.c 3
- xview.demos/color/color_objs.c 1
- xview.demos/color/x_draw.c 2
- xview.demos/cursor 1
- xview.demos/cursor/Imakefile 5
- xview.demos/cursor/Makefile 6
- xview.demos/cursor/hot_spot.c 4
- xview.demos/cursor/simple_cursor.c 5
- xview.demos/cursor/stop_cursor.c 5
- xview.demos/defaults 1
- xview.demos/defaults/Imakefile 5
- xview.demos/defaults/Makefile 6
- xview.demos/defaults/default_size.c 5
- xview.demos/defaults/default_text.c 5
- xview.demos/fonts 1
- xview.demos/fonts/Imakefile 5
- xview.demos/fonts/Makefile 6
- xview.demos/fonts/fonts.c 1
- xview.demos/fonts/simple_font.c 4
- xview.demos/fonts/type_font.c 4
- xview.demos/frames 1
- xview.demos/frames/Imakefile 5
- xview.demos/frames/Makefile 6
- xview.demos/frames/frame_color.c 6
- xview.demos/frames/simple_frame.c 6
- xview.demos/frames/subframe.c 6
- xview.demos/icons 1
- xview.demos/icons/Imakefile 6
- xview.demos/icons/Makefile 6
- xview.demos/icons/closed.icon 4
- xview.demos/icons/icon_demo.c 5
- xview.demos/icons/open.icon 5
- xview.demos/menus 1
- xview.demos/menus/Imakefile 5
- xview.demos/menus/Makefile 6
- xview.demos/menus/menu.c 4
- xview.demos/menus/menu_dir.c 3
- xview.demos/menus/menu_dir2.c 2
- xview.demos/menus/pin_menu.c 2
- xview.demos/menus/simple_menu.c 4
- xview.demos/menus/xv_menu.c 4
- xview.demos/misc 1
- xview.demos/misc/Imakefile 5
- xview.demos/misc/Makefile 6
- xview.demos/misc/drag_n_drop.c 3
- xview.demos/misc/fullscreen.c 4
- xview.demos/misc/screen.c 5
- xview.demos/misc/svrimage.c 5
- xview.demos/misc/type_to_string.c 5
- xview.demos/notice 1
- xview.demos/notice/Imakefile 5
- xview.demos/notice/Makefile 6
- xview.demos/notice/notice.c 3
- xview.demos/notice/simple_notice.c 5
- xview.demos/notice/trigger_notice.c 4
- xview.demos/notifier 1
- xview.demos/notifier/Imakefile 5
- xview.demos/notifier/Makefile 6
- xview.demos/notifier/animate.c 4
- xview.demos/notifier/interpose.c 5
- xview.demos/notifier/notify_input.c 5
- xview.demos/notifier/ntfy_do_dis.c 5
- xview.demos/notifier/ntfy_pipe.c 3
- xview.demos/notifier/ntfy_sig.c 5
- xview.demos/panels 1
- xview.demos/panels/Imakefile 4
- xview.demos/panels/Makefile 6
- xview.demos/panels/btn_menu.c 5
- xview.demos/panels/choices.c 3
- xview.demos/panels/client_data.c 5
- xview.demos/panels/item_move.c 1
- xview.demos/panels/list_glyphs.c 4
- xview.demos/panels/panel_repaint.c 4
- xview.demos/panels/repaint.c 5
- xview.demos/panels/simple_panel.c 5
- xview.demos/panels/stop_frame.c 5
- xview.demos/scrollbar 1
- xview.demos/scrollbar/Imakefile 5
- xview.demos/scrollbar/Makefile 6
- xview.demos/scrollbar/scroll_cells.c 1
- xview.demos/scrollbar/scroll_cells2.c 1
- xview.demos/seln_svc 1
- xview.demos/seln_svc/Imakefile 5
- xview.demos/seln_svc/Makefile 6
- xview.demos/seln_svc/long_seln.c 2
- xview.demos/seln_svc/seln.c 2
- xview.demos/seln_svc/seln_line.c 4
- xview.demos/seln_svc/simple_seln.c 4
- xview.demos/seln_svc/text_seln.c 3
- xview.demos/sv_compat 1
- xview.demos/sv_compat/Imakefile 5
- xview.demos/sv_compat/Makefile 6
- xview.demos/sv_compat/gray_stencil.pr 4
- xview.demos/sv_compat/pw_draw.c 4
- xview.demos/textsw 1
- xview.demos/textsw/Imakefile 6
- xview.demos/textsw/Makefile 6
- xview.demos/textsw/textsw.c 6
- xview.demos/textsw/textsw.font.c 3
- xview.demos/ttysw 1
- xview.demos/ttysw/Imakefile 5
- xview.demos/ttysw/Makefile 6
- xview.demos/ttysw/sample_tty.c 6
- xview.demos/ttysw/textsw_to_ttysw.c 5
- xview.demos/ttysw/ttycurses.c 1
- xview.demos/ttysw/xv_termsw.c 5
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # If this archive is complete, you will see the following message at the end:
- # "End of archive 1 (of 6)."
- # Contents: xview.demos xview.demos/canvas xview.demos/color
- # xview.demos/color/color_objs.c xview.demos/cursor
- # xview.demos/defaults xview.demos/fonts xview.demos/fonts/fonts.c
- # xview.demos/frames xview.demos/icons xview.demos/menus
- # xview.demos/misc xview.demos/notice xview.demos/notifier
- # xview.demos/panels xview.demos/panels/item_move.c
- # xview.demos/scrollbar xview.demos/scrollbar/scroll_cells.c
- # xview.demos/scrollbar/scroll_cells2.c xview.demos/seln_svc
- # xview.demos/sv_compat xview.demos/textsw xview.demos/ttysw
- # xview.demos/ttysw/ttycurses.c
- # Wrapped by argv@island on Thu Dec 7 23:18:13 1989
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test ! -d 'xview.demos' ; then
- echo shar: Creating directory \"'xview.demos'\"
- mkdir 'xview.demos'
- fi
- if test ! -d 'xview.demos/canvas' ; then
- echo shar: Creating directory \"'xview.demos/canvas'\"
- mkdir 'xview.demos/canvas'
- fi
- if test ! -d 'xview.demos/color' ; then
- echo shar: Creating directory \"'xview.demos/color'\"
- mkdir 'xview.demos/color'
- fi
- if test -f 'xview.demos/color/color_objs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/color/color_objs.c'\"
- else
- echo shar: Extracting \"'xview.demos/color/color_objs.c'\" \(8143 characters\)
- sed "s/^X//" >'xview.demos/color/color_objs.c' <<'END_OF_FILE'
- X/*
- X * color_objs.c --
- X * This program demonstrates the use of color in XView. It allows
- X * the user to choose the foreground and background colors of the
- X * various objects in an interactive manner.
- X */
- X#include <X11/Xlib.h>
- X#include <xview/xview.h>
- X#include <xview/svrimage.h>
- X#include <xview/textsw.h>
- X#include <xview/panel.h>
- X#include <xview/icon.h>
- X#include <xview/cms.h>
- X
- X#define SELECT_TEXTSW 0
- X#define SELECT_TEXTSW_VIEW 1
- X#define SELECT_SCROLLBAR 2
- X#define SELECT_PANEL 3
- X#define SELECT_ICON 4
- X
- X#define NUM_COLORS 8
- X
- X/* Icon data */
- Xstatic short icon_bits[256]={
- X#include "cardback.icon"
- X};
- X
- XPanel_item objects;
- XTextsw textsw;
- XPanel panel;
- XIcon icon;
- X
- X/*
- X * main()
- X * Create a panel and panel items. The application uses panel items
- X * to choose a particular object and change its foreground and
- X * background colors in an interactive manner. Create a textsw.
- X * Create an icon. All the objects share the same colormap segment.
- X */
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Panel_item panel_palette, panel_fg_bg;
- X Xv_cmsdata cms_data;
- X unsigned char red[NUM_COLORS], green[NUM_COLORS], blue[NUM_COLORS];
- X Server_image chips[NUM_COLORS], icon_image;
- X void color_notify();
- X extern void exit();
- X
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X /* Set up the RGB values and initialize the cms */
- X initialize_cms_data(&cms_data, red, green, blue);
- X
- X frame = (Frame)xv_create(NULL, FRAME,
- X FRAME_LABEL, argv[0],
- X NULL);
- X
- X /* Create panel and set the colormap segment on the panel */
- X panel = (Panel)xv_create(frame, PANEL,
- X PANEL_LAYOUT, PANEL_VERTICAL,
- X WIN_CMS_NAME, "palette",
- X WIN_CMS_DATA, &cms_data,
- X NULL);
- X
- X /* Create panel items */
- X objects = (Panel_item)xv_create(panel, PANEL_TOGGLE,
- X PANEL_LABEL_STRING, "Objects",
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_CHOICE_STRINGS, "Textsw", "Textsw View",
- X "Scrollbar", "Panel", "Icon", NULL,
- X NULL);
- X
- X panel_fg_bg = (Panel_item)xv_create(panel, PANEL_CHECK_BOX,
- X PANEL_LABEL_STRING, "Fg/Bg",
- X PANEL_CHOOSE_ONE, TRUE,
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_CHOICE_STRINGS, "Background", "Foreground", NULL,
- X NULL);
- X
- X /* Initialize colored chips to be used as panel choice images */
- X initialize_chips(panel, chips);
- X panel_palette = (Panel_item)xv_create(panel, PANEL_CHOICE,
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_LABEL_STRING, "Colors",
- X PANEL_CLIENT_DATA, panel_fg_bg,
- X XV_X, (int)xv_get(panel_fg_bg, XV_X),
- X PANEL_NEXT_ROW, 15,
- X PANEL_CHOICE_IMAGES,
- X chips[0], chips[1], chips[2], chips[3], chips[4],
- X chips[5], chips[6], chips[7], NULL,
- X PANEL_NOTIFY_PROC, color_notify,
- X NULL);
- X
- X (void) xv_create(panel, PANEL_BUTTON,
- X PANEL_LABEL_STRING, "Quit",
- X PANEL_NOTIFY_PROC, exit,
- X NULL);
- X (void)window_fit_height(panel);
- X
- X /* create textsw and set the colormap segment for it */
- X textsw = (Textsw)xv_create(frame, TEXTSW,
- X WIN_CMS_NAME, "palette",
- X WIN_BELOW, panel,
- X WIN_ROWS, 15,
- X WIN_COLUMNS, 80,
- X NULL);
- X
- X /* adjust panel dimensions */
- X (void)xv_set(panel, WIN_WIDTH, xv_get(textsw, WIN_WIDTH), NULL);
- X
- X icon_image = (Server_image)xv_create(NULL, SERVER_IMAGE,
- X XV_WIDTH, 64,
- X XV_HEIGHT, 64,
- X SERVER_IMAGE_DEPTH, 1,
- X SERVER_IMAGE_BITS, icon_bits,
- X NULL);
- X /* associate icon with the base frame */
- X icon = (Icon)xv_create(XV_NULL, ICON,
- X ICON_IMAGE, icon_image,
- X WIN_CMS_NAME, "palette",
- X NULL);
- X xv_set(frame, FRAME_ICON, icon, NULL);
- X
- X window_fit(frame);
- X
- X xv_main_loop(frame);
- X}
- X
- X/*
- X * initialize_cms_data()
- X * Initialize the colormap segment data and setup the RGB values.
- X */
- Xinitialize_cms_data(cms_data, red, green, blue)
- XXv_cmsdata *cms_data;
- Xunsigned char *red, *green, *blue;
- X{
- X /* white */ (red)[0] = 255; (green)[0] = 255; (blue)[0] = 255;
- X /* red */ (red)[1] = 255; (green)[1] = 0; (blue)[1] = 0;
- X /* green */ (red)[2] = 0; (green)[2] = 255; (blue)[2] = 0;
- X /* blue */ (red)[3] = 0; (green)[3] = 0; (blue)[3] = 255;
- X /* yellow */ (red)[4] = 255; (green)[4] = 255; (blue)[4] = 0;
- X /* brown */ (red)[5] = 188; (green)[5] = 143; (blue)[5] = 143;
- X /* gray */ (red)[6] = 220; (green)[6] = 220; (blue)[6] = 220;
- X /* black */ (red)[7] = 0; (green)[7] = 0; (blue)[7] = 0;
- X
- X cms_data->type = XV_STATIC_CMS;
- X cms_data->size = NUM_COLORS;
- X cms_data->rgb_count = NUM_COLORS;
- X cms_data->index = 0;
- X cms_data->red = red;
- X cms_data->green = green;
- X cms_data->blue = blue;
- X}
- X
- X/*
- X * initialize_chips()
- X * Create colored server images (pixmaps) to be used as
- X * panel choice images.
- X */
- Xinitialize_chips(panel, chips)
- XPanel panel;
- XServer_image chips[];
- X{
- X register int i;
- X Display *dpy = (Display *)xv_get(panel, XV_DISPLAY);
- X unsigned long mask, *pixels;
- X XGCValues values;
- X Pixmap pixmap;
- X GC gc;
- X
- X if (DefaultDepth(dpy, DefaultScreen(dpy)) == 1) {
- X puts("You need a color display to run this program");
- X exit(1);
- X }
- X /* setup gc for drawing colord squares (chips) */
- X values.graphics_exposures = False;
- X values.foreground = 1;
- X mask = GCGraphicsExposures | GCForeground;
- X gc = XCreateGC(dpy,
- X RootWindow(dpy, DefaultScreen(dpy)), mask, &values);
- X
- X /* Get the actual X pixel values from the colormap. The colormap
- X * has been installed on the panel, so use that. Any window with
- X * a cms colormap will do.
- X */
- X pixels = (unsigned long *)xv_get(panel, WIN_X_COLOR_INDICES);
- X for(i = 0; i < NUM_COLORS; i++) {
- X chips[i] = (Server_image)xv_create(XV_NULL, SERVER_IMAGE,
- X SERVER_IMAGE_COLORMAP, "palette",
- X XV_WIDTH, 16,
- X XV_HEIGHT, 16,
- X SERVER_IMAGE_DEPTH, 8,
- X NULL);
- X XSetForeground(dpy, gc, pixels[i]);
- X pixmap = (Pixmap)xv_get(chips[i], XV_XID);
- X XFillRectangle(dpy, pixmap, gc, 0, 0, 16, 16);
- X }
- X}
- X
- X/*
- X * This routine gets called when a color selection is made.
- X * Set the foreground or background on the currently selected object.
- X * WIN_FOREGROUND_COLOR & WIN_BACKGROUND_COLOR allow the application
- X * to specify indices into the colormap segment as the foreground
- X * and background values.
- X */
- Xvoid
- Xcolor_notify(panel_item, choice, event)
- XPanel_item panel_item;
- Xint choice;
- XEvent *event;
- X{
- X int cnt;
- X Xv_opaque get_object();
- X unsigned objs = (unsigned)xv_get(objects, PANEL_VALUE);
- X int fg = (int)xv_get(xv_get(panel_item, PANEL_CLIENT_DATA),
- X PANEL_VALUE);
- X
- X /* the value of the objects panel item is a bit mask ... "on" bits
- X * mean that the choice is selected. Get the object associated
- X * with the choice and set it's color. "&" tests bits in a mask.
- X */
- X for (cnt = 0; objs; cnt++, objs >>= 1)
- X if (objs & 1)
- X xv_set(get_object(cnt),
- X fg? WIN_FOREGROUND_COLOR : WIN_BACKGROUND_COLOR,
- X choice, NULL);
- X}
- X
- X/*
- X * Return the XView handle to nth object.
- X */
- XXv_opaque
- Xget_object(n)
- Xint n;
- X{
- X switch (n) {
- X case SELECT_TEXTSW:
- X return textsw;
- X case SELECT_TEXTSW_VIEW:
- X return xv_get(textsw, OPENWIN_NTH_VIEW, 0);
- X case SELECT_SCROLLBAR:
- X return xv_get(textsw, OPENWIN_VERTICAL_SCROLLBAR,
- X xv_get(textsw, OPENWIN_NTH_VIEW, 0));
- X case SELECT_PANEL:
- X return panel;
- X case SELECT_ICON:
- X return icon;
- X default:
- X return textsw;
- X }
- X}
- END_OF_FILE
- if test 8143 -ne `wc -c <'xview.demos/color/color_objs.c'`; then
- echo shar: \"'xview.demos/color/color_objs.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/color/color_objs.c'
- fi
- if test ! -d 'xview.demos/cursor' ; then
- echo shar: Creating directory \"'xview.demos/cursor'\"
- mkdir 'xview.demos/cursor'
- fi
- if test ! -d 'xview.demos/defaults' ; then
- echo shar: Creating directory \"'xview.demos/defaults'\"
- mkdir 'xview.demos/defaults'
- fi
- if test ! -d 'xview.demos/fonts' ; then
- echo shar: Creating directory \"'xview.demos/fonts'\"
- mkdir 'xview.demos/fonts'
- fi
- if test -f 'xview.demos/fonts/fonts.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/fonts/fonts.c'\"
- else
- echo shar: Extracting \"'xview.demos/fonts/fonts.c'\" \(7864 characters\)
- sed "s/^X//" >'xview.demos/fonts/fonts.c' <<'END_OF_FILE'
- X/*
- X * fonts.c -- provide an interface for the user to pick and choose
- X * between font families and styles known to XView. The program
- X * provides several panel buttons to choose between font types, and
- X * a canvas window in which the user can type. The characters typed
- X * are printed in the current font. If a font "name" is specified,
- X * then the family, style and size are ignored. Using the SELECT
- X * button on the canvas window positions the current typing location
- X * at the x,y coordinates of the button-down event.
- X */
- X#include <ctype.h>
- X#include <X11/X.h>
- X#include <X11/Xlib.h>
- X#include <xview/xview.h>
- X#include <xview/panel.h>
- X#include <xview/font.h>
- X
- XDisplay *dpy;
- XGC gc;
- XXFontStruct *cur_font;
- XPanel_item family_item, style_item, scale_item, name_item;
- Xint canvas_width;
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Panel panel;
- X Canvas canvas;
- X XGCValues gcvalues;
- X Xv_Font font;
- X void change_font();
- X void my_event_proc(), my_resize_proc();
- X int change_font_by_name();
- X extern void exit();
- X
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X frame = (Frame)xv_create(XV_NULL, FRAME,
- X FRAME_LABEL, argv[0],
- X FRAME_SHOW_FOOTER, TRUE,
- X NULL);
- X
- X panel = (Panel)xv_create(frame, PANEL,
- X PANEL_LAYOUT, PANEL_VERTICAL,
- X NULL);
- X (void) xv_create(panel, PANEL_BUTTON,
- X PANEL_LABEL_STRING, "Quit",
- X PANEL_NOTIFY_PROC, exit,
- X NULL);
- X family_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
- X PANEL_LABEL_STRING, "Family",
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
- X PANEL_CHOICE_STRINGS,
- X FONT_FAMILY_DEFAULT, FONT_FAMILY_DEFAULT_FIXEDWIDTH,
- X FONT_FAMILY_LUCIDA, FONT_FAMILY_LUCIDA_FIXEDWIDTH,
- X FONT_FAMILY_ROMAN, FONT_FAMILY_SERIF, FONT_FAMILY_COUR,
- X FONT_FAMILY_CMR, FONT_FAMILY_GALLENT,
- X FONT_FAMILY_OLGLYPH, FONT_FAMILY_OLCURSOR, NULL,
- X PANEL_NOTIFY_PROC, change_font,
- X NULL);
- X style_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
- X PANEL_LABEL_STRING, "Style",
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
- X PANEL_CHOICE_STRINGS,
- X FONT_STYLE_DEFAULT, FONT_STYLE_NORMAL, FONT_STYLE_BOLD,
- X FONT_STYLE_ITALIC, FONT_STYLE_BOLD_ITALIC, NULL,
- X PANEL_NOTIFY_PROC, change_font,
- X NULL);
- X scale_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
- X PANEL_LABEL_STRING, "Scale",
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
- X PANEL_CHOICE_STRINGS,
- X "Small", "Medium", "Large", "X-Large", NULL,
- X PANEL_NOTIFY_PROC, change_font,
- X NULL);
- X name_item = (Panel_item)xv_create(panel, PANEL_TEXT,
- X PANEL_LABEL_STRING, "Font Name:",
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_VALUE_DISPLAY_LENGTH, 20,
- X PANEL_NOTIFY_PROC, change_font_by_name,
- X NULL);
- X window_fit(panel);
- X
- X canvas = (Canvas)xv_create(frame, CANVAS,
- X XV_WIDTH, 400,
- X XV_HEIGHT, 200,
- X CANVAS_X_PAINT_WINDOW, TRUE,
- X CANVAS_RESIZE_PROC, my_resize_proc,
- X NULL);
- X xv_set(canvas_paint_window(canvas),
- X WIN_EVENT_PROC, my_event_proc,
- X WIN_CONSUME_EVENT, LOC_WINENTER,
- X NULL);
- X
- X window_fit(frame);
- X
- X dpy = (Display *)xv_get(frame, XV_DISPLAY);
- X font = (Xv_Font)xv_get(frame, XV_FONT);
- X cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
- X xv_set(frame, FRAME_LEFT_FOOTER, xv_get(font, FONT_NAME), NULL);
- X
- X gcvalues.font = cur_font->fid;
- X gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- X gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
- X gcvalues.graphics_exposures = False;
- X gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
- X GCForeground | GCBackground | GCFont | GCGraphicsExposures,
- X &gcvalues);
- X
- X xv_main_loop(frame);
- X}
- X
- Xvoid
- Xmy_event_proc(win, event)
- XXv_Window win;
- XEvent *event;
- X{
- X static int x = 10, y = 10;
- X Window xwin = (Window)xv_get(win, XV_XID);
- X char c;
- X
- X if (event_is_up(event))
- X return;
- X
- X if (event_is_ascii(event)) {
- X c = (char)event_action(event);
- X XDrawString(dpy, xwin, gc, x, y, &c, 1);
- X /* advance x to next position. If over edge, linewrap */
- X if ((x += XTextWidth(cur_font, &c, 1)) >= canvas_width) {
- X y += cur_font->max_bounds.ascent +
- X cur_font->max_bounds.descent;
- X x = 10;
- X }
- X } else if (event_action(event) == ACTION_SELECT) {
- X x = event_x(event);
- X y = event_y(event);
- X } else if (event_action(event) == LOC_WINENTER)
- X win_set_kbd_focus(win, xwin);
- X}
- X
- X/*
- X * check resizing so we know how wide to allow the user to type.
- X */
- Xvoid
- Xmy_resize_proc(canvas, width, height)
- XCanvas canvas;
- Xint width, height;
- X{
- X canvas_width = width;
- X}
- X
- Xvoid
- Xchange_font(item, value, event)
- XPanel_item item;
- XEvent *event;
- X{
- X static int family, style, scale;
- X char buf[128];
- X Frame frame;
- X char *family_name;
- X char *style_name;
- X int scale_value;
- X Xv_Font font;
- X
- X frame = (Frame)xv_get(xv_get(item, PANEL_PARENT_PANEL), XV_OWNER);
- X family_name = (char *)xv_get(family_item, PANEL_CHOICE_STRING,
- X xv_get(family_item, PANEL_VALUE));
- X style_name = (char *)xv_get(style_item, PANEL_CHOICE_STRING,
- X xv_get(style_item, PANEL_VALUE));
- X scale_value = (int) xv_get(scale_item, PANEL_VALUE);
- X xv_set(frame, FRAME_BUSY, TRUE, NULL);
- X font = (Xv_Font)xv_find(frame, FONT,
- X FONT_FAMILY, family_name,
- X FONT_STYLE, style_name,
- X /* scale_value happens to coincide with Window_rescale_state */
- X FONT_SCALE, scale_value,
- X FONT_SIZES_FOR_SCALE, 12, 14, 16, 22,
- X NULL);
- X xv_set(frame, FRAME_BUSY, FALSE, NULL);
- X
- X if (!font) {
- X if (item == family_item) {
- X sprintf(buf, "cannot load '%s'", family_name);
- X xv_set(family_item, PANEL_VALUE, family, NULL);
- X } else if (item == style_item) {
- X sprintf(buf, "cannot load '%s'", style_name);
- X xv_set(style_item, PANEL_VALUE, style, NULL);
- X } else {
- X sprintf(buf, "Not available in %s scale.",
- X xv_get(scale_item, PANEL_CHOICE_STRING, scale));
- X xv_set(scale_item, PANEL_VALUE, scale, NULL);
- X }
- X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
- X return;
- X }
- X if (item == family_item)
- X family = value;
- X else if (item == style_item)
- X style = value;
- X else
- X scale = value;
- X cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
- X XSetFont(dpy, gc, cur_font->fid);
- X sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
- X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
- X}
- X
- Xchange_font_by_name(item, event)
- XPanel_item item;
- XEvent *event;
- X{
- X char buf[128];
- X char *name = panel_get_value(item);
- X Frame frame = (Frame)xv_get(xv_get(item, XV_OWNER), XV_OWNER);
- X Xv_Font font;
- X
- X xv_set(frame, FRAME_BUSY, TRUE, NULL);
- X font = (Xv_Font)font = (Xv_Font)xv_find(frame, FONT,
- X FONT_NAME, name,
- X NULL);
- X xv_set(frame, FRAME_BUSY, FALSE, NULL);
- X
- X if (!font) {
- X sprintf(buf, "cannot load '%s'", name);
- X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
- X return PANEL_NONE;
- X }
- X cur_font = (XFontStruct *)xv_get(font, FONT_INFO);
- X XSetFont(dpy, gc, cur_font->fid);
- X sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
- X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
- X return PANEL_NONE;
- X}
- END_OF_FILE
- if test 7864 -ne `wc -c <'xview.demos/fonts/fonts.c'`; then
- echo shar: \"'xview.demos/fonts/fonts.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/fonts/fonts.c'
- fi
- if test ! -d 'xview.demos/frames' ; then
- echo shar: Creating directory \"'xview.demos/frames'\"
- mkdir 'xview.demos/frames'
- fi
- if test ! -d 'xview.demos/icons' ; then
- echo shar: Creating directory \"'xview.demos/icons'\"
- mkdir 'xview.demos/icons'
- fi
- if test ! -d 'xview.demos/menus' ; then
- echo shar: Creating directory \"'xview.demos/menus'\"
- mkdir 'xview.demos/menus'
- fi
- if test ! -d 'xview.demos/misc' ; then
- echo shar: Creating directory \"'xview.demos/misc'\"
- mkdir 'xview.demos/misc'
- fi
- if test ! -d 'xview.demos/notice' ; then
- echo shar: Creating directory \"'xview.demos/notice'\"
- mkdir 'xview.demos/notice'
- fi
- if test ! -d 'xview.demos/notifier' ; then
- echo shar: Creating directory \"'xview.demos/notifier'\"
- mkdir 'xview.demos/notifier'
- fi
- if test ! -d 'xview.demos/panels' ; then
- echo shar: Creating directory \"'xview.demos/panels'\"
- mkdir 'xview.demos/panels'
- fi
- if test -f 'xview.demos/panels/item_move.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/panels/item_move.c'\"
- else
- echo shar: Extracting \"'xview.demos/panels/item_move.c'\" \(9801 characters\)
- sed "s/^X//" >'xview.demos/panels/item_move.c' <<'END_OF_FILE'
- X/*
- X * item_move.c
- X * Move items around in a panel using an event handler specific
- X * to the panel. Two panels are created -- the left panel contains
- X * panel buttons that allow you to create certain types of items that
- X * are put in the second panel. Use the ADJUST mouse button to move
- X * items around in the second panel.
- X */
- X#include <stdio.h>
- X#include <xview/xview.h>
- X#include <xview/panel.h>
- X
- X/* we need handles to the base frame and a panel -- instead of using
- X * global variables, we're going to attach the objects to the objects
- X * which need to reference them. Attach using XV_KEY_DATA --
- X * here are the keys.
- X */
- X#define PACKAGE_KEY 100
- X#define FRAME_KEY 101
- X#define PANEL_KEY 102
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Panel panel;
- X Panel_item create_text, item;
- X void quit(), my_event_proc();
- X int selected(), create_item();
- X
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X frame = (Frame)xv_create(XV_NULL, FRAME,
- X FRAME_LABEL, "Use Middle Button To Move Items",
- X FRAME_SHOW_FOOTER, TRUE,
- X NULL);
- X /*
- X * Create panel for known panel items. Layout panel vertically.
- X */
- X panel = (Panel)xv_create(frame, PANEL,
- X PANEL_LAYOUT, PANEL_VERTICAL,
- X NULL);
- X
- X /*
- X * Create the standard "Quit" button to exit program.
- X */
- X (void) xv_create(panel, PANEL_BUTTON,
- X PANEL_LABEL_STRING, "Quit",
- X PANEL_NOTIFY_PROC, quit,
- X XV_KEY_DATA, FRAME_KEY, frame,
- X NULL);
- X
- X /*
- X * create text panel item, attach the frame as client data for
- X * use by the notify procedure create_item(). Text items inherit
- X * the layout of "label" and "value" from its parent panel.
- X * override for the text item by setting PANEL_LAYOUT explicitly.
- X */
- X create_text = (Panel_item)xv_create(panel, PANEL_TEXT,
- X PANEL_LABEL_STRING, "Create Button:",
- X PANEL_NOTIFY_PROC, create_item,
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_VALUE_DISPLAY_LENGTH, 10,
- X NULL);
- X
- X /*
- X * panel button determines which type of button to create -- a
- X * button or a message item. See create_item().
- X */
- X item = (Panel_item)xv_create(panel, PANEL_CHOICE,
- X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X PANEL_LABEL_STRING, "Item type",
- X PANEL_CHOICE_STRINGS, "Button", "Message", "Text", NULL,
- X NULL);
- X window_fit(panel);
- X
- X /* Create a new panel to be used for panel creation. The panel
- X * from above is no longer referenced. The panel created here
- X * is the panel used throughout the rest of this program. The
- X * panel referenced in WIN_RIGHT_OF and XV_HEIGHT is the old one
- X * since the new one isn't created yet.
- X */
- X panel = (Panel)xv_create(frame, PANEL,
- X WIN_RIGHT_OF, canvas_paint_window(panel),
- X XV_WIDTH, 300,
- X XV_HEIGHT, xv_get(panel, XV_HEIGHT),
- X OPENWIN_SHOW_BORDERS, TRUE,
- X NULL);
- X
- X /* Install event handling routine for the panel */
- X xv_set(canvas_paint_window(panel),
- X WIN_EVENT_PROC, my_event_proc,
- X XV_KEY_DATA, PANEL_KEY, panel,
- X NULL);
- X /* attach various items to the text item for text_select() */
- X xv_set(create_text,
- X XV_KEY_DATA, FRAME_KEY, frame,
- X XV_KEY_DATA, PACKAGE_KEY, item,
- X XV_KEY_DATA, PANEL_KEY, panel,
- X NULL);
- X window_fit(frame);
- X xv_main_loop(frame);
- X}
- X
- X/*
- X * Process events for the panel's subwindow. This routine gets -all-
- X * events that occur in the panel subwindow and does not interfere
- X * with the normal processing of events dispatched to panels items.
- X * my_event_proc is only interested in ADJUST button events that
- X * happen on top of panel items. When the user clicks and _drags_ the
- X * ADJUST button on a panel item, the item is moved to where the mouse
- X * moves to.
- X */
- Xvoid
- Xmy_event_proc(window, event)
- XXv_Window window;
- XEvent *event;
- X{
- X static Panel_item item;
- X static int x_offset, y_offset;
- X Panel panel = (Panel)xv_get(window, XV_KEY_DATA, PANEL_KEY);
- X Frame frame = (Frame)xv_get(panel, XV_OWNER);
- X Rect *rect, *item_rect;
- X char buf[64];
- X
- X /*
- X * If the mouse is dragging an item, reset its new location.
- X */
- X if (event_action(event) == LOC_DRAG && item) {
- X Panel_item pi;
- X Rect r;
- X /*
- X * Get the rect of item, then *copy* it -- never change data
- X * returned by xv_get(). Modify the copied rect reflecting
- X * new X,Y position of panel item and check to see if it
- X * intersects with any existing panel items.
- X */
- X rect = (Rect *)xv_get(item, XV_RECT);
- X rect_construct(&r, /* see <xview/rect.h> for macros */
- X rect->r_left, rect->r_top, rect->r_width, rect->r_height);
- X r.r_left = event->ie_locx - x_offset;
- X r.r_top = event->ie_locy - y_offset;
- X PANEL_EACH_ITEM(panel, pi)
- X if (pi == item)
- X continue;
- X /* don't let panel items overlap */
- X item_rect = (Rect *)xv_get(pi, XV_RECT);
- X if (rect_intersectsrect(item_rect, &r))
- X return;
- X PANEL_END_EACH
- X /* no overlap -- move panel item. */
- X xv_set(item,
- X PANEL_ITEM_X, r.r_left,
- X PANEL_ITEM_Y, r.r_top,
- X NULL);
- X }
- X /* If it's not the ADJUST button, we're not interested */
- X if (event_action(event) != ACTION_ADJUST)
- X return;
- X /*
- X * next two cases is ADJUST button just-down or just-released
- X */
- X if (event_is_down(event)) {
- X /* Middle button down on an item -- determine panel item */
- X PANEL_EACH_ITEM(panel, item)
- X rect = (Rect *)xv_get(item, XV_RECT);
- X if (rect_includespoint(rect,
- X event->ie_locx, event->ie_locy)) {
- X x_offset = event->ie_locx - rect->r_left;
- X y_offset = event->ie_locy - rect->r_top;
- X break;
- X }
- X PANEL_END_EACH
- X if (item)
- X sprintf(buf, "Moving item: '%s'",
- X (char *)xv_get(item, PANEL_LABEL_STRING));
- X else
- X buf[0] = 0;
- X } else if (item) {
- X char *name = (char *)xv_get(item, PANEL_LABEL_STRING);
- X
- X /* test if item is inside panel by comparing XV_RECTs */
- X rect = (Rect *)xv_get(panel, XV_RECT);
- X if (!rect_includespoint(rect,
- X event->ie_locx + rect->r_left,
- X event->ie_locy + rect->r_top)) {
- X /* item is outside the panel -- remove item */
- X xv_destroy(item);
- X sprintf(buf, "Removed '%s' from panel", name);
- X } else
- X sprintf(buf, "'%s' moved to %d %d", name,
- X (int)xv_get(item, XV_X), (int)xv_get(item, XV_Y));
- X /* set "item" to null so that new drag
- X * events don't attempt to move old item.
- X */
- X item = NULL;
- X }
- X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
- X}
- X
- X/*
- X * Callback routine for all panel buttons except "Quit".
- X * If the panel item is the text item, determine the name of the new
- X * panel button the user wishes to create. Loop through all the
- X * existing panel items looking for one with the same label. If so,
- X * return PANEL_NONE and set the frame's footer with an error message.
- X * Otherwise, create a new panel item with the label, reset the text
- X * item value and return PANEL_NEXT.
- X */
- Xint
- Xcreate_item(item, event)
- XPanel_item item;
- XEvent *event;
- X{
- X Xv_pkg *pkg;
- X Panel panel = (Panel)xv_get(item, XV_KEY_DATA, PANEL_KEY);
- X Frame frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
- X Panel_item pi, pkg_item;
- X char buf[64];
- X
- X pkg_item = (Panel_item)xv_get(item, XV_KEY_DATA, PACKAGE_KEY);
- X (void) strncpy(buf, xv_get(item, PANEL_VALUE), sizeof buf);
- X if (!buf[0])
- X return PANEL_NONE;
- X switch((int)xv_get(pkg_item, PANEL_VALUE)) {
- X case 1: pkg = PANEL_MESSAGE; break;
- X case 2: pkg = PANEL_TEXT; break;
- X default: pkg = PANEL_BUTTON;
- X }
- X /* loop thru all panel items and check for item with same name */
- X PANEL_EACH_ITEM(panel, pi)
- X if (!strcmp(buf, xv_get(pi, PANEL_LABEL_STRING))) {
- X xv_set(frame, FRAME_LEFT_FOOTER, "Label Taken", NULL);
- X return PANEL_NONE;
- X }
- X PANEL_END_EACH
- X (void) xv_create(panel, pkg,
- X PANEL_LABEL_STRING, buf,
- X PANEL_NOTIFY_PROC, selected,
- X XV_KEY_DATA, FRAME_KEY, frame,
- X /* only for text items, but doesn't affect other items */
- X PANEL_VALUE_DISPLAY_LENGTH, 10,
- X PANEL_LAYOUT, PANEL_HORIZONTAL,
- X NULL);
- X xv_set(item, PANEL_VALUE, "", NULL);
- X return PANEL_NEXT;
- X}
- X
- X/*
- X * For panel buttons. return XV_OK or XV_ERROR if the item was
- X * selected using the left mouse button or not.
- X */
- Xint
- Xselected(item, event)
- XPanel_item item;
- XEvent *event;
- X{
- X Frame frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
- X char buf[64];
- X
- X if (event_action(event) == ACTION_SELECT) {
- X sprintf(buf, "'%s' selected", xv_get(item, PANEL_LABEL_STRING));
- X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
- X return XV_OK;
- X }
- X return XV_ERROR;
- X}
- X
- X/*
- X * callback for the "Quit" item. Destroy the frame, which
- X * causes xv_main_loop() to return.
- X */
- Xvoid
- Xquit(item, event)
- XPanel_item item;
- XEvent *event;
- X{
- X Frame frame = (Frame)xv_get(item, XV_KEY_DATA, FRAME_KEY);
- X if (event_action(event) == ACTION_SELECT)
- X xv_destroy_safe(frame);
- X}
- END_OF_FILE
- if test 9801 -ne `wc -c <'xview.demos/panels/item_move.c'`; then
- echo shar: \"'xview.demos/panels/item_move.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/panels/item_move.c'
- fi
- if test ! -d 'xview.demos/scrollbar' ; then
- echo shar: Creating directory \"'xview.demos/scrollbar'\"
- mkdir 'xview.demos/scrollbar'
- fi
- if test -f 'xview.demos/scrollbar/scroll_cells.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/scrollbar/scroll_cells.c'\"
- else
- echo shar: Extracting \"'xview.demos/scrollbar/scroll_cells.c'\" \(8544 characters\)
- sed "s/^X//" >'xview.demos/scrollbar/scroll_cells.c' <<'END_OF_FILE'
- X/*
- X * scroll_cells.c -- scroll a bitmap of cells around in a canvas.
- X * The cells are rectangular areas labeled with numbers which may
- X * represent arbitrary data such as icon images. The cell sizes are
- X * defined to be 64 by 64 aligned in rows and columns. This example
- X * is used to demonstrate how to configure scrollbars to accommodate
- X * arbitrary data within a window.
- X */
- X#include <stdio.h>
- X#include <X11/X.h>
- X#include <X11/Xlib.h> /* Using Xlib graphics */
- X#include <xview/xview.h>
- X#include <xview/canvas.h>
- X#include <xview/scrollbar.h>
- X#include <xview/font.h>
- X#include <xview/xv_xrect.h>
- X
- X#define CELL_WIDTH 64
- X#define CELL_HEIGHT 64
- X#define CELLS_PER_HOR_PAGE 5 /* when paging w/scrollbar */
- X#define CELLS_PER_VER_PAGE 5 /* when paging w/scrollbar */
- X#define CELLS_PER_ROW 8
- X#define CELLS_PER_COL 16
- X
- XPixmap cell_map; /* pixmap copied onto canvas window */
- XScrollbar horiz_scrollbar;
- XScrollbar vert_scrollbar;
- XGC gc; /* General usage GC */
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Canvas canvas;
- X void repaint_proc();
- X
- X /* Initialize, create frame and canvas... */
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X frame = (Frame)xv_create(XV_NULL, FRAME,
- X FRAME_LABEL, argv[0],
- X FRAME_SHOW_FOOTER, TRUE,
- X NULL);
- X
- X canvas = (Canvas)xv_create(frame, CANVAS,
- X /* make subwindow the size of a "page" */
- X XV_WIDTH, CELL_WIDTH * CELLS_PER_HOR_PAGE,
- X XV_HEIGHT, CELL_HEIGHT * CELLS_PER_VER_PAGE,
- X /* canvas is much larger than the window */
- X CANVAS_WIDTH, CELL_WIDTH * CELLS_PER_ROW + 1,
- X CANVAS_HEIGHT, CELL_HEIGHT * CELLS_PER_COL + 1,
- X CANVAS_AUTO_EXPAND, FALSE,
- X CANVAS_AUTO_SHRINK, FALSE,
- X /* don't retain window -- we'll need
- X * to repaint it all the time */
- X CANVAS_RETAINED, FALSE,
- X /* we're using Xlib graphics calls in repaint_proc() */
- X CANVAS_X_PAINT_WINDOW, TRUE,
- X CANVAS_REPAINT_PROC, repaint_proc,
- X /* we'll be repainting over exposed areas,
- X * so don't bother clearing */
- X OPENWIN_AUTO_CLEAR, FALSE,
- X NULL);
- X
- X /*
- X * Create scrollbars attached to the canvas. When user clicks
- X * on cable, page by the page size (PAGE_LENGTH). Scrolling
- X * should move cell by cell, not by one pixel (PIXELS_PER_UNIT).
- X */
- X vert_scrollbar = xv_create(canvas, SCROLLBAR,
- X SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
- X SCROLLBAR_PIXELS_PER_UNIT, CELL_HEIGHT,
- X SCROLLBAR_OBJECT_LENGTH, CELLS_PER_COL,
- X SCROLLBAR_PAGE_LENGTH, CELLS_PER_VER_PAGE,
- X SCROLLBAR_VIEW_LENGTH, CELLS_PER_VER_PAGE,
- X NULL);
- X horiz_scrollbar = xv_create(canvas, SCROLLBAR,
- X SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
- X SCROLLBAR_PIXELS_PER_UNIT, CELL_WIDTH,
- X SCROLLBAR_OBJECT_LENGTH, CELLS_PER_ROW,
- X SCROLLBAR_PAGE_LENGTH, CELLS_PER_HOR_PAGE,
- X SCROLLBAR_VIEW_LENGTH, CELLS_PER_HOR_PAGE,
- X NULL);
- X
- X /*
- X * create pixmap and draw cells into it ... this is the abstraction.
- X * The cell_map is copied into the window via XCopyPlane in the
- X * repaint procedure.
- X */
- X {
- X short x, y, pt = 0;
- X Xv_Font font;
- X XPoint points[256]; /* keep Xlib calls to a minimum */
- X XGCValues gcvalues;
- X Display *dpy = (Display *)xv_get(canvas, XV_DISPLAY);
- X
- X font = (Xv_Font)xv_find(frame, FONT,
- X FONT_NAME, "icon",
- X XV_AUTO_CREATE, FALSE,
- X NULL);
- X cell_map = XCreatePixmap(dpy, DefaultRootWindow(dpy),
- X CELLS_PER_ROW * CELL_WIDTH + 1,
- X CELLS_PER_COL * CELL_HEIGHT + 1,
- X 1); /* We only need a 1-bit deep pixmap */
- X
- X /* Create the gc for the cell_map -- since it is 1-bit deep,
- X * use 0 and 1 for fg/bg values. Also, limit number of
- X * events generated by setting graphics exposures to False.
- X */
- X gcvalues.graphics_exposures = False;
- X gcvalues.background = 0;
- X gcvalues.foreground = 1;
- X if (font)
- X gcvalues.font = (Font)xv_get(font, XV_XID);
- X gc = XCreateGC(dpy, cell_map,
- X GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
- X
- X if (!font) {
- X /* dot every other pixel */
- X for (x = 0; x <= CELL_WIDTH * CELLS_PER_ROW; x += 2)
- X for (y = 0; y <= CELL_HEIGHT * CELLS_PER_COL; y += 2) {
- X if (x % CELL_WIDTH != 0 && y % CELL_HEIGHT != 0)
- X continue;
- X points[pt].x = x, points[pt].y = y;
- X if (++pt == sizeof points / sizeof points[0]) {
- X XDrawPoints(dpy, cell_map, gc, points, pt,
- X CoordModeOrigin);
- X pt = 0;
- X }
- X }
- X if (pt != sizeof points) /* flush remaining points */
- X XDrawPoints(dpy, cell_map, gc,
- X points, pt, CoordModeOrigin);
- X }
- X /* Icon font not available. Instead, label each cell
- X * with a string describing the cell's coordinates.
- X */
- X for (x = 0; x < CELLS_PER_ROW; x++)
- X for (y = 0; y < CELLS_PER_COL; y++) {
- X char buf[8];
- X if (!font) {
- X sprintf(buf, "%d,%d", x+1, y+1);
- X XDrawString(dpy, cell_map, gc,
- X x * CELL_WIDTH + 5, y * CELL_HEIGHT + 25,
- X buf, strlen(buf));
- X } else {
- X buf[0] = x + y * CELLS_PER_COL;
- X XDrawString(dpy, cell_map, gc,
- X x * CELL_WIDTH, y * CELL_HEIGHT, buf, 1);
- X }
- X }
- X /* we're now done with the cell_map, so free gc and create
- X * a new one based on the window that will use it. Otherwise,
- X * the GC may not work because of different depths.
- X */
- X if (font)
- X xv_destroy(gc);
- X XFreeGC(dpy, gc);
- X gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
- X gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- X gcvalues.plane_mask = 1L;
- X gc = XCreateGC(dpy, DefaultRootWindow(dpy),
- X GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
- X }
- X
- X /* shrink frame to minimal size and start notifier */
- X window_fit(frame);
- X xv_main_loop(frame);
- X}
- X
- X/*
- X * The repaint procedure is called whenever repainting is needed in
- X * a paint window. Since the canvas is not retained, this routine
- X * is going to be called anytime the user scrolls the canvas. The
- X * canvas will handle repainting the portion of the canvas that
- X * was in view and has scrolled onto another viewable portion of
- X * the window. The xrects parameter will cover the new areas that
- X * were not in view before and have just scrolled into view. If
- X * the window resizes or if the window is exposed by other windows
- X * disappearing or cycling through the window tree, then the number
- X * of xrects will be more than one and we'll have to copy the new
- X * areas one by one. Clipping isn't necessary since the areas to
- X * be rendered are set by the xrects value.
- X */
- Xvoid
- Xrepaint_proc(canvas, paint_window, dpy, win, xrects)
- XCanvas canvas;
- XXv_Window paint_window;
- XDisplay *dpy;
- XWindow win;
- XXv_xrectlist *xrects;
- X{
- X int x, y;
- X
- X x = (int)xv_get(horiz_scrollbar, SCROLLBAR_VIEW_START);
- X y = (int)xv_get(vert_scrollbar, SCROLLBAR_VIEW_START);
- X
- X for (xrects->count--; xrects->count >= 0; xrects->count--) {
- X printf("top-left cell = %d, %d -- %d,%d %d,%d\n", x+1, y+1,
- X xrects->rect_array[xrects->count].x,
- X xrects->rect_array[xrects->count].y,
- X xrects->rect_array[xrects->count].width,
- X xrects->rect_array[xrects->count].height);
- X
- X XCopyPlane(dpy, cell_map, win, gc,
- X xrects->rect_array[xrects->count].x,
- X xrects->rect_array[xrects->count].y,
- X xrects->rect_array[xrects->count].width,
- X xrects->rect_array[xrects->count].height,
- X xrects->rect_array[xrects->count].x,
- X xrects->rect_array[xrects->count].y, 1L);
- X }
- X}
- END_OF_FILE
- if test 8544 -ne `wc -c <'xview.demos/scrollbar/scroll_cells.c'`; then
- echo shar: \"'xview.demos/scrollbar/scroll_cells.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/scrollbar/scroll_cells.c'
- fi
- if test -f 'xview.demos/scrollbar/scroll_cells2.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/scrollbar/scroll_cells2.c'\"
- else
- echo shar: Extracting \"'xview.demos/scrollbar/scroll_cells2.c'\" \(8148 characters\)
- sed "s/^X//" >'xview.demos/scrollbar/scroll_cells2.c' <<'END_OF_FILE'
- X/*
- X * scroll_cells2.c -- scroll a bitmap of cells around in a canvas.
- X * This is a simplified version of scroll_cells.c graphically. That
- X * is, it does not display icons, just rows and columns of cells.
- X * The difference with this version is that it attempts to accomodate
- X * resize events not addressed in the scroll_cells.c.
- X * This new function is at the end of the file.
- X */
- X#include <stdio.h>
- X#include <X11/X.h>
- X#include <X11/Xlib.h> /* Using Xlib graphics */
- X#include <xview/xview.h>
- X#include <xview/canvas.h>
- X#include <xview/scrollbar.h>
- X#include <xview/xv_xrect.h>
- X
- X#define CELL_WIDTH 64
- X#define CELL_HEIGHT 64
- X#define CELLS_PER_HOR_PAGE 5 /* when paging w/scrollbar */
- X#define CELLS_PER_VER_PAGE 5 /* when paging w/scrollbar */
- X#define CELLS_PER_ROW 16
- X#define CELLS_PER_COL 16
- X
- XPixmap cell_map; /* pixmap copied onto canvas window */
- XScrollbar horiz_scrollbar;
- XScrollbar vert_scrollbar;
- XGC gc; /* General usage GC */
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Canvas canvas;
- X void repaint_proc(), resize_proc();
- X
- X /* Initialize, create frame and canvas... */
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X frame = xv_create(XV_NULL, FRAME,
- X FRAME_LABEL, argv[0],
- X FRAME_SHOW_FOOTER, TRUE,
- X NULL);
- X
- X canvas = xv_create(frame, CANVAS,
- X /* make subwindow the size of a "page" */
- X XV_WIDTH, CELL_WIDTH * CELLS_PER_HOR_PAGE,
- X XV_HEIGHT, CELL_HEIGHT * CELLS_PER_VER_PAGE,
- X /* canvas is much larger than the window */
- X CANVAS_WIDTH, CELL_WIDTH * CELLS_PER_HOR_PAGE,
- X CANVAS_HEIGHT, CELL_HEIGHT * CELLS_PER_VER_PAGE,
- X /* CANVAS_AUTO_EXPAND, FALSE, */
- X /* CANVAS_AUTO_SHRINK, FALSE, */
- X /* don't retain window -- we'll repaint it all the time */
- X CANVAS_RETAINED, FALSE,
- X /* We're using Xlib graphics calls in repaint_proc() */
- X CANVAS_X_PAINT_WINDOW, TRUE,
- X CANVAS_REPAINT_PROC, repaint_proc,
- X CANVAS_RESIZE_PROC, resize_proc,
- X OPENWIN_AUTO_CLEAR, FALSE,
- X NULL);
- X
- X /*
- X * Create scrollbars attached to the canvas. When user clicks
- X * on cable, page by the page size (PAGE_LENGTH). Scrolling
- X * should move cell by cell, not by one pixel (PIXELS_PER_UNIT).
- X */
- X vert_scrollbar = xv_create(canvas, SCROLLBAR,
- X SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
- X SCROLLBAR_PIXELS_PER_UNIT, CELL_HEIGHT,
- X NULL);
- X horiz_scrollbar = xv_create(canvas, SCROLLBAR,
- X SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
- X SCROLLBAR_PIXELS_PER_UNIT, CELL_WIDTH,
- X NULL);
- X
- X /*
- X * create pixmap and draw cells into it. This portion of the
- X * program could use XCopyArea to render real icons whose sizes
- X * do not exceed whatever CELL_WIDTH and CELL_HEIGHT are defined
- X * to be. The cell_map will be copied into the window via
- X * XCopyPlane in the repaint procedure.
- X */
- X {
- X short x, y, pt = 0;
- X XPoint points[256];
- X XGCValues gcvalues;
- X Display *dpy = (Display *)xv_get(canvas, XV_DISPLAY);
- X
- X cell_map = XCreatePixmap(dpy, DefaultRootWindow(dpy),
- X CELLS_PER_ROW * CELL_WIDTH + 1,
- X CELLS_PER_COL * CELL_HEIGHT + 1,
- X 1); /* We only need a 1-bit deep pixmap */
- X
- X /* Create the gc for the cell_map -- since it is 1-bit deep,
- X * use 0 and 1 for fg/bg values. Also, limit number of
- X * events generated by setting geraphics exposures to False.
- X */
- X gcvalues.graphics_exposures = False;
- X gcvalues.background = 0;
- X gcvalues.foreground = 1;
- X gc = XCreateGC(dpy, cell_map,
- X GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
- X
- X /* dot every other pixel */
- X for (x = 0; x <= CELL_WIDTH * CELLS_PER_ROW; x += 2)
- X for (y = 0; y <= CELL_HEIGHT * CELLS_PER_COL; y += 2) {
- X if (x % CELL_WIDTH != 0 && y % CELL_HEIGHT != 0)
- X continue;
- X points[pt].x = x, points[pt].y = y;
- X if (++pt == sizeof points / sizeof points[0]) {
- X XDrawPoints(dpy, cell_map, gc,
- X points, pt, CoordModeOrigin);
- X pt = 0;
- X }
- X }
- X if (pt != sizeof points) /* flush out the remaining points */
- X XDrawPoints(dpy, cell_map, gc,
- X points, pt, CoordModeOrigin);
- X /* label each cell indicating the its coordinates */
- X for (x = 0; x < CELLS_PER_ROW; x++)
- X for (y = 0; y < CELLS_PER_COL; y++) {
- X char buf[8];
- X sprintf(buf, "%d,%d", x+1, y+1);
- X XDrawString(dpy, cell_map, gc,
- X x * CELL_WIDTH + 5, y * CELL_HEIGHT + 25,
- X buf, strlen(buf));
- X }
- X /* we're now done with the cell_map, so free gc and
- X * create a new one based on the window that will use it.
- X */
- X XFreeGC(dpy, gc);
- X gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
- X gcvalues.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- X gcvalues.plane_mask = 1L;
- X gc = XCreateGC(dpy, DefaultRootWindow(dpy),
- X GCForeground|GCBackground|GCGraphicsExposures, &gcvalues);
- X }
- X
- X /* shrink frame to minimal size and start notifier */
- X window_fit(frame);
- X xv_main_loop(frame);
- X}
- X
- X/*
- X * The repaint procedure is called whenever repainting is needed in
- X * a paint window. Since the canvas is not retained, this routine
- X * is going to be called anytime the user scrolls the canvas. The
- X * canvas will handle repainting the portion of the canvas that
- X * was in view and has scrolled onto another viewable portion of
- X * the window. The xrects parameter will cover the new areas that
- X * were not in view before and have just scrolled into view. If
- X * the window resizes or if the window is exposed by other windows
- X * disappearing or cycling thru the window tree, then the number
- X * of xrects will be more than one and we'll have to copy the new
- X * areas one by one. Clipping isn't necessary since the areas to
- X * be rendered are set by the xrects value.
- X */
- Xvoid
- Xrepaint_proc(canvas, paint_window, dpy, win, xrects)
- XCanvas canvas;
- XXv_Window paint_window;
- XDisplay *dpy;
- XWindow win;
- XXv_xrectlist *xrects;
- X{
- X int x, y;
- X
- X x = (int)xv_get(horiz_scrollbar, SCROLLBAR_VIEW_START);
- X y = (int)xv_get(vert_scrollbar, SCROLLBAR_VIEW_START);
- X
- X for (xrects->count--; xrects->count >= 0; xrects->count--) {
- X printf("top-left cell = %d, %d -- %d,%d %d,%d\n", x+1, y+1,
- X xrects->rect_array[xrects->count].x,
- X xrects->rect_array[xrects->count].y,
- X xrects->rect_array[xrects->count].width,
- X xrects->rect_array[xrects->count].height);
- X
- X XCopyPlane(dpy, cell_map, win, gc,
- X x * CELL_WIDTH,
- X y * CELL_HEIGHT,
- X xv_get(paint_window, XV_WIDTH),
- X xv_get(paint_window, XV_HEIGHT),
- X 0, 0, 1L);
- X }
- X}
- X
- X/*
- X * If the application is resized, then we may wish to reset the
- X * paging and viewing parameters for the scrollbars.
- X */
- Xvoid
- Xresize_proc(canvas, new_width, new_height)
- XCanvas canvas;
- Xint new_width, new_height;
- X{
- X int page_w = (int)(new_width/CELL_WIDTH);
- X int page_h = (int)(new_height/CELL_HEIGHT);
- X
- X if (!vert_scrollbar || !horiz_scrollbar)
- X return;
- X
- X printf("new width/height in cells: w = %d, h = %d\n",
- X page_w, page_h);
- X
- X xv_set(horiz_scrollbar,
- X SCROLLBAR_OBJECT_LENGTH, CELLS_PER_ROW,
- X SCROLLBAR_PAGE_LENGTH, page_w,
- X SCROLLBAR_VIEW_LENGTH, page_w,
- X NULL);
- X xv_set(vert_scrollbar,
- X SCROLLBAR_OBJECT_LENGTH, CELLS_PER_COL,
- X SCROLLBAR_PAGE_LENGTH, page_h,
- X SCROLLBAR_VIEW_LENGTH, page_h,
- X NULL);
- X}
- END_OF_FILE
- if test 8148 -ne `wc -c <'xview.demos/scrollbar/scroll_cells2.c'`; then
- echo shar: \"'xview.demos/scrollbar/scroll_cells2.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/scrollbar/scroll_cells2.c'
- fi
- if test ! -d 'xview.demos/seln_svc' ; then
- echo shar: Creating directory \"'xview.demos/seln_svc'\"
- mkdir 'xview.demos/seln_svc'
- fi
- if test ! -d 'xview.demos/sv_compat' ; then
- echo shar: Creating directory \"'xview.demos/sv_compat'\"
- mkdir 'xview.demos/sv_compat'
- fi
- if test ! -d 'xview.demos/textsw' ; then
- echo shar: Creating directory \"'xview.demos/textsw'\"
- mkdir 'xview.demos/textsw'
- fi
- if test ! -d 'xview.demos/ttysw' ; then
- echo shar: Creating directory \"'xview.demos/ttysw'\"
- mkdir 'xview.demos/ttysw'
- fi
- if test -f 'xview.demos/ttysw/ttycurses.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'xview.demos/ttysw/ttycurses.c'\"
- else
- echo shar: Extracting \"'xview.demos/ttysw/ttycurses.c'\" \(3296 characters\)
- sed "s/^X//" >'xview.demos/ttysw/ttycurses.c' <<'END_OF_FILE'
- X/*
- X * ttycurses.c -- An application that uses a tty subwindow that
- X * emulates a tty so well, you can use curses(3x) routines in it.
- X * This program does not handle resizes -- resizing the base frame
- X * produces unpredictable results. To handle resizing properly,
- X * the application should install a resize event handler and
- X * call endwin() followed by initscr() to reinitialize curses
- X * to reflect the size of the window.
- X *
- X * cc ttycurses.c -lxview -lcurses -ltermlib
- X */
- X#include <curses.h>
- X#undef WINDOW /* defined by curses.h -- needs to be undefined */
- X#include <xview/xview.h>
- X#include <xview/panel.h>
- X#include <xview/textsw.h>
- X#include <xview/tty.h>
- X
- X/* panel items contain the x,y info for outputting text to the ttysw */
- XPanel_item x, y, text;
- X
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X Frame frame;
- X Panel panel;
- X Tty ttysw;
- X char buf[16];
- X void output(), exit();
- X
- X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
- X
- X frame = xv_create(XV_NULL, FRAME,
- X FRAME_LABEL, argv[0],
- X FRAME_SHOW_FOOTER, TRUE,
- X NULL);
- X
- X panel = (Frame)xv_create(frame, PANEL, NULL);
- X (void) xv_create(panel, PANEL_BUTTON,
- X PANEL_LABEL_STRING, "Quit",
- X PANEL_NOTIFY_PROC, exit,
- X NULL);
- X (void) xv_create(panel, PANEL_BUTTON,
- X PANEL_LABEL_STRING, "Print",
- X PANEL_NOTIFY_PROC, output,
- X NULL);
- X x = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
- X PANEL_LABEL_STRING, "X:",
- X PANEL_VALUE_DISPLAY_LENGTH, 3,
- X NULL);
- X y = (Panel_item)xv_create(panel, PANEL_NUMERIC_TEXT,
- X PANEL_LABEL_STRING, "Y:",
- X PANEL_VALUE_DISPLAY_LENGTH, 3,
- X NULL);
- X text = (Panel_item)xv_create(panel, PANEL_TEXT,
- X PANEL_LABEL_STRING, "Text:",
- X PANEL_VALUE_DISPLAY_LENGTH, 10,
- X PANEL_VALUE, "X",
- X NULL);
- X window_fit(panel);
- X
- X ttysw = (Tty)xv_create(frame, TTY,
- X WIN_BELOW, panel,
- X WIN_X, 0,
- X TTY_ARGV, TTY_ARGV_DO_NOT_FORK,
- X NULL);
- X window_fit(frame);
- X
- X dup2((int)xv_get(ttysw, TTY_TTY_FD), 0); /* dup2 closes 0 first */
- X dup2((int)xv_get(ttysw, TTY_TTY_FD), 1); /* dup2 closes 1 first */
- X
- X /* initscr() initializes the curses package and determines
- X * characteristics about the window as if it were a terminal.
- X * The curses specific variables, LINES and COLS are now set
- X * to the row and column sizes of the window.
- X */
- X initscr();
- X
- X xv_set(x, PANEL_MAX_VALUE, COLS-1, NULL);
- X xv_set(y, PANEL_MAX_VALUE, LINES-1, NULL);
- X sprintf(buf, "LINES: %d", LINES-1);
- X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
- X sprintf(buf, "COLS: %d", COLS-1);
- X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
- X
- X xv_main_loop(frame);
- X}
- X/*
- X * callback routine for the <print> panel button. Get the corrdinates
- X * and the text to print on the tty subwindow and use curses library
- X * routines to render the text.
- X */
- Xvoid
- Xoutput()
- X{
- X int X = (int)xv_get(x, PANEL_VALUE);
- X int Y = (int)xv_get(y, PANEL_VALUE);
- X char *Text = (char *)xv_get(text, PANEL_VALUE);
- X mvaddstr(Y, X, Text);
- X refresh();
- X}
- END_OF_FILE
- if test 3296 -ne `wc -c <'xview.demos/ttysw/ttycurses.c'`; then
- echo shar: \"'xview.demos/ttysw/ttycurses.c'\" unpacked with wrong size!
- fi
- # end of 'xview.demos/ttysw/ttycurses.c'
- fi
- echo shar: End of archive 1 \(of 6\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 3 4 5 6 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 6 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-